/**
 * @author xieyue
 * @date 创建时间：2015年1月29日 上午11:13:52
 * @version 1.0
 */
package com.ciwong.epaper.modules.me.adapter;

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.ciwong.epaper.R;

import java.util.List;


public class ListViewAdapter extends BaseAdapter {
    private Context mContext;
    private List<String> datas;
    private LayoutInflater mInflater;
    private int[] iconArray = {R.mipmap.my_info_icon, R.mipmap.contact_phone, R.mipmap.icn_tousu,R.mipmap.about_us_icon, R.mipmap.icn_about, R.mipmap.about_us_icon};

    public ListViewAdapter(Context mContext, List<String> datas) {
        this.mContext = mContext;
        this.datas = datas;
        mInflater = LayoutInflater.from(mContext);
    }

    @SuppressLint("NewApi")
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        final ViewHolder holder;
        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.item_listview, null);
            holder = new ViewHolder();
            holder.itemView = convertView.findViewById(R.id.item_entrance_name);
            holder.tx_service_number = convertView.findViewById(R.id.tx_service_number);
            holder.img_arrow_right = convertView.findViewById(R.id.img_arrow_right);
            holder.img_entrance_type = convertView.findViewById(R.id.img_entrance_type);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        holder.itemView.setText(datas.get(position));

        if (position < iconArray.length) {
            holder.img_entrance_type.setImageResource(iconArray[position]);
        }
        holder.tx_service_number.setVisibility(View.GONE);
        holder.img_arrow_right.setVisibility(View.VISIBLE);
        return convertView;
    }

    @Override
    public int getCount() {
        return datas.size();
    }

    @Override
    public Object getItem(int position) {
        return datas.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    class ViewHolder {
        TextView itemView;
        ImageView img_entrance_type;
        TextView tx_service_number;
        ImageView img_arrow_right;

    }


}
